package com.ruoyi.lvlian.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.lvlian.domain.MapLabel;
import com.ruoyi.lvlian.service.IMapLabelService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 地图标签Controller
 *
 * @author ruoyi
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/label")
@Api(value = "地图标签", tags = "地图标签MapLabelController")
public class MapLabelController extends BaseController {
    @Autowired
    private IMapLabelService mapLabelService;

    /**
     * 查询地图标签列表
     */
    //@RequiresPermissions("lvlian:label:list")
    @GetMapping("/list")
    public TableDataInfo list(MapLabel mapLabel) {
        startPage();
        List<MapLabel> list = mapLabelService.selectMapLabelList(mapLabel);
        return getDataTable(list);
    }


    @ApiOperation("获取地图标签详细信息")
    @GetMapping("/getInfoByPosition")
    public AjaxResult getInfoByPosition(@ApiParam(value = "position", required = true) @RequestParam(value = "position") String position) {
        return success(mapLabelService.selectMapLabelByPosition(position));
    }


    /**
     * 修改地图标签
     */
    @Log(title = "地图标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MapLabel mapLabel) {
        if ( mapLabel.getPosition() == null  || StringUtils.isEmpty( mapLabel.getParkAdr())) {
            return error("信息不能为空");
        }

        return toAjax(mapLabelService.updateMapLabel(mapLabel));
    }

    /**
     * 删除地图标签
     */
    //@RequiresPermissions("lvlian:label:remove")
    @Log(title = "地图标签", businessType = BusinessType.DELETE)
    @DeleteMapping("/{positions}")
    public AjaxResult remove(@PathVariable String[] positions) {
        return toAjax(mapLabelService.deleteMapLabelByPositions(positions));
    }
}
